package com.atguigu.cloud.controller;


import com.atguigu.cloud.entities.Pay;
import com.atguigu.cloud.entities.PayDTO;
import com.atguigu.cloud.resp.ResultData;
import com.atguigu.cloud.service.PayService;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @auther zzyy
 * @create 2023-11-03 18:55
 */
@RestController
public class PayController{
    @Resource PayService payService;
    @PostMapping(value = "/pay/add")
    public ResultData<Integer> addPay(@RequestBody Pay pay){
        System.out.println(pay.toString());
        int i = payService.add(pay);
        return ResultData.success(i);
    }
    @DeleteMapping(value = "/pay/del/{id}")
    public ResultData<Integer> deletePay(@PathVariable("id") Integer id) {
        return  ResultData.success(payService.delete(id));
    }
    @PutMapping(value = "/pay/update")
    public ResultData<String> updatePay(@RequestBody PayDTO payDTO){
        Pay pay = new Pay();
        BeanUtils.copyProperties(payDTO, pay);

        int i = payService.update(pay);
        return  ResultData.success("成功修改记录，返回值："+i);
    }
    @GetMapping(value = "/pay/get/{id}")
    public ResultData<Pay> getById(@PathVariable("id") Integer id){
        return ResultData.success(payService.getById(id));
    }
    @GetMapping(value = "/pay/getAll")
    public ResultData<List<Pay>> getAll(){
        return ResultData.success(payService.getAll());
    }

    @Value("${info.msg}")
    private String info;

    @Value("${server.port}")
    private String port;

    @GetMapping(value = "/pay/getinfo")
    public String getInfo(){
        return info + port;
    }

}





